package resource.pojo;

import java.io.Serializable;
import java.sql.ResultSet;
import java.util.ArrayList;
import models.util.MySqlDataAccessHelper;

public class GroupApprove implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String idGroupApprove;
	private Boolean statusUse;
	private String groupName;
	private String description;
	private boolean delete = false;
	private boolean add = false;
	private boolean isRead = true;
	private ArrayList<ListApprove> allListApprove = new ArrayList<ListApprove>();
//	UtilInitLang utilInitLang = new UtilInitLang();
	MySqlDataAccessHelper mysqlHelper=new MySqlDataAccessHelper();

	public MySqlDataAccessHelper getMysqlHelper() {
		return mysqlHelper;
	}

	public void setMysqlHelper(MySqlDataAccessHelper mysqlHelper) {
		this.mysqlHelper = mysqlHelper;
	}

	public GroupApprove() {
	}

	public GroupApprove(String idGroupApprove, Boolean statusUse,
			String groupName, String description) {
		this.idGroupApprove = idGroupApprove;
		this.statusUse = statusUse;
		this.groupName = groupName;
		this.description = description;
	}

	public String getIdGroupApprove() {
		return idGroupApprove;
	}

	public void setIdGroupApprove(String idGroupApprove) {
		this.idGroupApprove = idGroupApprove;
	}

	public String getGroupName() {
		return groupName;
	}

	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public boolean isDelete() {
		return delete;
	}

	public void setDelete(boolean delete) {
		this.delete = delete;
	}

	public boolean isAdd() {
		return add;
	}

	public void setAdd(boolean add) {
		this.add = add;
	}

	public ArrayList<ListApprove> getAllListApprove() {
		if (isRead()) {
			mysqlHelper.open();
			try {
				String sql = "select * from listapprove where IDGroupApprove='"
						+ this.getIdGroupApprove()
						+ "' order by listapprove.`Order` asc";
				ResultSet rs = mysqlHelper.executeQuery(sql);
				while (rs.next()) {
					allListApprove.add(new ListApprove(rs.getInt("ID"), rs
							.getString("IDGroupApprove"), rs.getString("IDEmployee"),
							rs.getInt("IDtypeApprove"), rs.getInt("Order"),rs
									.getInt("IDStatus"), rs
									.getDate("DateApprove"), rs
									.getString("Description")));
					
				}
			} catch (Exception e) {
				e.printStackTrace();
			}finally{
				mysqlHelper.close();
			}
		}
		setRead(false);
		return allListApprove;
	}

	public void setAllListApprove(ArrayList<ListApprove> allListApprove) {
		this.allListApprove = allListApprove;
	}

	public boolean isRead() {
		return isRead;
	}

	public void setRead(boolean isRead) {
		this.isRead = isRead;
	}

	public Boolean getStatusUse() {
		return statusUse;
	}

	public void setStatusUse(Boolean statusUse) {
		this.statusUse = statusUse;
	}

	@Override
	public String toString() {
		return this.groupName;
	}
}
